<template>
  <tr class="count">
    <td colspan="7">
      <div class="jiesuan clearfix">
        <div class="left fl">
          <p>
            <input
              type="checkbox"
              name=""
              class="choose_all"
              @change="isAll"
              :checked="select"
            />
            全选&nbsp;&nbsp;&nbsp;<a
              href="#"
              class="del_check"
              @click="checkDelete"
              >删除选中商品</a
            >
          </p>
        </div>
        <div class="right fr clearfix">
          <p>商品总计：￥{{ oldSum.toFixed(2) }}</p>
          <p>活动优惠：-￥{{ Preferential.toFixed(2) }}</p>
          <p>
            已选商品<span class="red t-number"> {{ quantity }}</span
            >件 总价(不含运费、税费)：<span class="red t-price"
              >￥{{ sum.toFixed(2) }}</span
            >
          </p>
          <!-- <div><a href="#" class="btn pay">结算</a></div> -->
          <a href="#" class="btn pay fr">结算</a>
        </div>
      </div>
    </td>
  </tr>
</template>
<script>
export default {
  name: 'TodoFooter',
  props: {
    list: {
      type: Array,
      required: true,
    },
  },
  methods: {
    isAll() {
      this.$emit('isAll')
    },
    checkDelete() {
      this.$emit('checkDelete')
    },
  },
  computed: {
    sum() {
      return this.list.reduce((prev, item) => {
        return prev + item.price * item.count
      }, 0)
    },
    Preferential() {
      return this.list.reduce((prev, item) => {
        return prev + (item.oldPrice - item.price) * item.count
      }, 0)
    },
    oldSum() {
      return this.list.reduce((prev, item) => {
        return prev + item.oldPrice * item.count
      }, 0)
    },
    quantity() {
      return this.list.reduce((prev, item) => {
        return prev + item.count
      }, 0)
    },
    select() {
      return this.list.every((item) => item.isSelected)
    },
  },
}
</script>
<style lang="less" scoped></style>
